<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.4</version>
    </parent>

    <groupId>org.springframework.samples</groupId>
    <artifactId>spring-petclinic-microservices</artifactId>
    <version>3.2.4</version>
    <name>${project.artifactId}</name>
    <packaging>pom</packaging>

    <modules>
        <module>spring-petclinic-admin-server</module>
        <module>spring-petclinic-customers-service</module>
        <module>spring-petclinic-vets-service</module>
        <module>spring-petclinic-visits-service</module>
        <module>spring-petclinic-config-server</module>
        <module>spring-petclinic-discovery-server</module>
        <module>spring-petclinic-api-gateway</module>
    </modules>

    <properties>
        <java.version>17</java.version>

        <spring-cloud.version>2023.0.1</spring-cloud.version>
        <chaos-monkey-spring-boot.version>2.3.10</chaos-monkey-spring-boot.version>
        <jolokia-core.version>1.7.1</jolokia-core.version>

        <!-- Workaround for resolving the issue while using the provided lombok dependency in upgraded Java version.
        Should be removed while future upgrading-->
        <lombok.version>1.18.30</lombok.version>

        <docker.image.prefix>springcommunity</docker.image.prefix>
        <docker.image.exposed.port>9090</docker.image.exposed.port>
        <docker.image.dockerfile.dir>${basedir}</docker.image.dockerfile.dir>
        <!-- podman is also supported -->
        <container.executable>docker</container.executable>
        <!-- By default, the OCI image is build for the linux/amd64 platform -->
        <!-- For Apple Silicon M2 Chip you have to change it to the linux/arm64 -->
        <container.platform>linux/amd64</container.platform>
        <!-- The -load option is a shortcut for or -output=type=docker -->
        <!-- Could be changed by the -push option !-->
        <container.build.extraarg>--load</container.build.extraarg>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>chaos-monkey-spring-boot</artifactId>
                <version>${chaos-monkey-spring-boot.version}</version>
            </dependency>
            <dependency>
                <groupId>org.jolokia</groupId>
                <artifactId>jolokia-core</artifactId>
                <version>${jolokia-core.version}</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <profiles>
        <profile>
            <id>springboot</id>
            <activation>
                <file>
                    <!-- Just a way to identify a Spring Boot application -->
                    <exists>src/main/resources/application.yml</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <!-- Spring Boot Actuator displays build-related information if a META-INF/build-info.properties file is present -->
                                <goals>
                                    <goal>build-info</goal>
                                </goals>
                                <configuration>
                                    <additionalProperties>
                                        <encoding.source>${project.build.sourceEncoding}</encoding.source>
                                        <encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
                                        <java.version>${java.version}</java.version>
                                    </additionalProperties>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Spring Boot Actuator displays build-related information if a META-INF/build-info.properties file is present -->
                    <plugin>
                        <groupId>io.github.git-commit-id</groupId>
                        <artifactId>git-commit-id-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>revision</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <verbose>true</verbose>
                            <dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
                            <generateGitPropertiesFile>true</generateGitPropertiesFile>
                            <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
                            <failOnNoGitDirectory>false</failOnNoGitDirectory>
                            <failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>buildDocker</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <version>3.1.1</version>
                            <executions>
                                <execution>
                                    <id>docker-build</id>
                                    <phase>install</phase>
                                    <goals>
                                        <goal>exec</goal>
                                    </goals>
                                    <configuration>
                                        <executable>${container.executable}</executable>
                                        <workingDirectory>${docker.image.dockerfile.dir}</workingDirectory>
                                        <arguments>
                                            <argument>build</argument>
                                            <argument>-f</argument>
                                            <argument>Dockerfile</argument>
                                            <argument>--build-arg</argument>
                                            <argument>ARTIFACT_NAME=${project.build.finalName}</argument>
                                            <argument>--build-arg</argument>
                                            <argument>EXPOSED_PORT=${docker.image.exposed.port}</argument>
                                            <argument>--platform</argument>
                                            <argument>${container.platform}</argument>
                                            <argument>${container.build.extraarg}</argument>
                                            <argument>-t</argument>
                                            <argument>${docker.image.prefix}/${project.artifactId}</argument>
                                            <argument>${project.build.directory}</argument>
                                        </arguments>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>

</project>
